const client = require('../../client');
const { WorkflowOpenAPIResponse } = require('./openapi_resp');

class QueryWorkflowRequest{
    constructor(keyword, pageNum = 1, pageSize =10) {
        this.keyword = keyword;
        this.pageNum = pageNum;
        this.pageSize = pageSize;
    }
}

class QueryWorkflowHeaders {
    constructor(commonHeaders = {}, regionId = '') {
        this.commonHeaders = commonHeaders;
        this.regionId = regionId;
    }
}

class QueryWorkflowService {
    constructor(client) {
        this.client = client; 
    } 

    async queryWorkflow(request, headers) {
        const url = `/workflow/openapi/v1/workflow`; // OPEN API函数详情查询接口URL
        const params = {
            keyword: request.keyword,
            pageNum: request.pageNum,
            pageSize: request.pageSize
        }; 

        const config = {
            method: 'GET',
            url,
            headers: {
                ...headers.commonHeaders,
                'Regionid': headers.regionId,
                'Content-Type': 'application/json'
            },
            params, // 即Credentials的入参query
        }

        const res = await this.client.doRequest(config);
        // 收到JSON字对象，检查returnObj是否为空
        const queryRes = new WorkflowOpenAPIResponse(res);
        console.log("query workflow return: ", queryRes.returnObj);
        return queryRes; // 返回响应对象
    }
}

module.exports = {
    QueryWorkflowRequest: QueryWorkflowRequest,
    QueryWorkflowHeaders: QueryWorkflowHeaders,
    QueryWorkflowService: QueryWorkflowService,
}